package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author ttao
 * @since 2023/4/23 11:15
 */

@Mapper
public interface DishMapper {
    /**
     * 根据分类查询菜品数量
     */
    @Select("select count(id) from dish where category_id=#{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 菜品管理分页条件查询
     *
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> queryPage(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 添加菜品
     *
     * @param dish
     * @return
     */
    @Insert("insert into dish (name, category_id, price, image, description, status, create_time, update_time, create_user, update_user) VALUES " +
            "(#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @Options(keyProperty = "id", useGeneratedKeys = true)
    @AutoFill(OperationType.INSERT)
    int insert(Dish dish);

    /**
     * 菜品批量删除
     *
     * @param ids
     * @return
     */
    int deleteByIds(List<Long> ids);

    /**
     * 根据id查询菜品信息
     *
     * @param id
     * @return
     */
    @Select("select * from dish where id=#{id}")
    Dish selectById(Long id);

    /**
     * 修改菜品
     *
     * @param dish
     * @return
     */
    @AutoFill(OperationType.UPDATE)
    int updateById(Dish dish);

    /**
     * 根据分类id查询对应菜品
     *
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id=#{categoryId}")
    List<DishVO> selectByCategoryId(Long categoryId);

    /**
     * 条件查询菜品列表
     *
     * @param dish
     * @return
     */
    List<Dish> list(Dish dish);
}

